<template>
  <view class="container">
	<!-- 头部 -->
	<view class="header">
		<view class="mesg" @click="handlemsg">
			<image src="../../static/msg.png" alt="">
		</view>
		<view class="bg-image">
			<swiper :indicator-dots="false" :autoplay="true" :interval="3000"  :duration="1000">
				<swiper-item v-for="item in imgList">
					<image :src="item.image_url" mode=""></image>
				</swiper-item>
			</swiper>
		</view>
	</view>
	<view class="p">
		<view class="totip" >
			<view class="image1">
				<image src="../../static/tip.png" alt="">
			</view>
			<view class="text_tip">
				<swiper :indicator-dots="false" :autoplay="true" :interval="3000" vertical :duration="1000">
					<swiper-item v-for="item in g_list" @click="jumpUrl(item.help_id)">
						{{item.title}}
					</swiper-item>
				</swiper>
				<!-- 小程序即将上线啦！ -->
			</view>
			<view class="image2">
				<image src="../../static/right.png" alt="">
			</view>
		</view>
		
		<view class="type">
			<view class="title">
				回收赚钱
			</view>
			<view class="type_l">
				<view class="type_t" v-for="(item,index) in list" :key="item.id" @click="recovery(index,item.category_id)">
					<view class="t_image">
						<image :src='item.image.external_url' alt="">
					</view>
					<view class="type_text">
						{{item.name}}
					</view>
				</view>
			</view>
		</view>
	</view>
	
    <!-- 店铺页面组件 -->
    <!-- <Page :items="items" /> -->
  </view>
</template>

<script>
  import { setCartTabBadge } from '@/core/app'
  import * as Api from '@/api/recovery'
  import Page from '@/components/page'

  const App = getApp()

  export default {
    components: {
      Page
    },
    data() {
      return {
        // 页面参数
        options: {},
        // 页面属性
        page: {},
        // 页面元素
        items: [],
		list:[
			{
				id:1,
				name:'塑料',
				image:'../../static/66.png'
			},
			{
				id:2,
				name:'衣服',
				image:'../../static/77.png'
			},{
				id:3,
				name:'玻璃制品',
				image:'../../static/88.png'
			},
			{
				id:4,
				name:'纸类',
				image:'../../static/99.png'
			},{
				id:5,
				name:'金属',
				image:'../../static/111.png'
			},{
				id:6,
				name:'其他',
				image:'../../static/112.png'
			}
		],
		g_list:[],
		imgList:[]
      }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
      // 当前页面参数
      this.options = options
      // 加载页面数据
      this.getPageData();
      this.getTip();
	  this.getCategoryImage()
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      // 更新购物车角标
      setCartTabBadge()
    },

    methods: {
		/* 消息 */
		handlemsg(){
			console.log(123)
			uni.navigateTo({
				url:'/pages/message-center/index'
			})
		},
		detail(){
			uni.navigateTo({
				url:'/pages/msgdetail/index'
			})
		},
		jumpUrl(e){
			console.log(111)
			uni.navigateTo({
				url:'/pages/totip/index?t_id='+e
			})
		},
		// 回收
		recovery(n,m){
			uni.navigateTo({
				url:'/pages/recovery/index?i_key='+n+'&c_id='+m
			})
		},
      /**
       * 加载页面数据
       * @param {Object} callback
       */
      getPageData(callback) {
        const app = this
        const pageId = app.options.pageId || 0
        Api.wasteCategory()
          .then(result => {
			  console.log(result)
			  this.list=result.data.list
          })
          .finally(() => callback && callback())
      },
	  
	  // 获取公告
	 getTip(callback) {
        const app = this
        const pageId = app.options.pageId || 0
        Api.help()
          .then(result => {
			  console.log(result)
			  this.g_list=result.data.list.data
          })
          .finally(() => callback && callback())
      },
	  // 轮播图
	  getCategoryImage(callback) {
	     const app = this
	     // const pageId = app.options.pageId || 0
	     Api.waste_categoryImage()
	       .then(result => {
	  			  console.log(result)
				  app.imgList=result.data.list
	  			  // this.g_list=result.data.list.data
	       })
	       .finally(() => callback && callback())
	   },
	  
      /**
       * 设置顶部导航栏
       */
      setPageBar() {
        const {
          page
        } = this
        // 设置页面标题
        // uni.setNavigationBarTitle({
        //   title: page.params.title
        // });
        // 设置navbar标题、颜色
        uni.setNavigationBarColor({
          frontColor: page.style.titleTextColor === 'white' ? '#ffffff' : '#000000',
          backgroundColor: page.style.titleBackgroundColor
        })
      },

    },

    /**
     * 下拉刷新
     */
    onPullDownRefresh() {
      // 获取首页数据
      this.getPageData(() => {
        uni.stopPullDownRefresh()
      })
    },

    /**
     * 分享当前页面
     */
    onShareAppMessage() {
      const app = this
      const { page } = app
      return {
        title: page.params.share_title,
        path: "/pages/index/index?" + app.$getShareUrlParams()
      }
    },

    /**
     * 分享到朋友圈
     * 本接口为 Beta 版本，暂只在 Android 平台支持，详见分享到朋友圈 (Beta)
     * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
     */
    onShareTimeline() {
      const app = this
      const { page } = app
      return {
        title: page.params.share_title,
        path: "/pages/index/index?" + app.$getShareUrlParams()
      }
    },
	
	
  }
</script>

<style lang="scss" scoped>
	.bg-image{
		uni-swiper {
		    display: block;
		    width: 686rpx !important;
		    height: 326rpx !important;
			image{
				width: 100%;
				height: 100%;
			}
		}
	}
	.text_tip {
		uni-swiper {
		    display: block;
		    height: 36rpx !important;
		}
	}
  .container {
    background: #F5F5F5;
	.header{
		width: 750rpx;
		height: 284rpx;
		background: #66B347;
		border-radius: 0px 0px 100rpx 100rpx;
		padding: 32rpx;
		.bg-image{
			width: 686rpx;
			height: 326rpx;
			background: #1ABC9C;
			border-radius: 20rpx;
			margin: 0 auto;
			margin-top: 50rpx;
			// background-image: url(../../static/s_bg.png);
		}
		.mesg{
			width: 29rpx;
			height: 35rpx;
			text-align: right;
			float: right;
			image{
				width: 100%;
				height: 100%;
			}
			
		}
	}
	.p{
		padding: 32rpx;
		margin-top: 120rpx;
		.totip{
			width: 686rpx;
			height: 96rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 20rpx 32rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.image1{
				width: 47rpx;
				height: 47rpx;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.text_tip{
				width: 376rpx;
				font-size: 28rpx;
				font-family: Adobe Heiti Std;
				font-weight: normal;
				color: #333333;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
			.image2{
				width: 22rpx;
				height: 37rpx;
				image{
					width: 100%;
					height: 100%;
				}
			}
		}
		.type{
			width: 686rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			margin-top: 30rpx;
			.title{
				height: 30rpx;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
				line-height: 30rpx;
				padding: 32rpx;
			}
			.type_l{
				display: flex;
				flex-wrap: wrap;
				.type_t{
					width: 297rpx;
					height: 224rpx;
					border: 1rpx solid #66B347;
					border-radius: 20rpx;
					margin: 23rpx;
					text-align: center;
					padding: 40rpx;
					.t_image{
						width: 94rpx;
						height: 90rpx;
						margin: 0 auto;
						image{
							width: 100%;
							height: 100%;
						}
					}
					.type_text{
						margin-top: 15rpx;
					}
				}
			}
			
		}
	}
	
  }
</style>
